#pragma once
#include "resource.h"       // main symbols
#include "ImportProgressObserver.h"
#include "ThumbnailWindow.h"

class CImportProgressObserverTrampolineWnd;

class CImportProgressDialog : 
	public CDialogImpl<CImportProgressDialog>,
	public ImportProgressObserver
{
	CImportProgressObserverTrampolineWnd *_pTrampolineWnd;
	ImportProgressObserver *_pObserver;
	CThumbnailWindow _thumbnail;
	HANDLE _hThread;

public:
	CImportProgressDialog()
		: _pTrampolineWnd(NULL), _pObserver(NULL), _hThread(NULL)
	{
	}

	~CImportProgressDialog()
	{
	}

	enum { IDD = IDD_IMPORTPROGRESSDIALOG };

BEGIN_MSG_MAP(CImportProgressDialog)
	MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
	MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
	COMMAND_HANDLER(IDCANCEL, BN_CLICKED, OnClickedCancel)
END_MSG_MAP()

// Handler prototypes:
//  LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
//  LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
//  LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);

	LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnClickedCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);

public:
	void AddDroppedFile(const CString &strPath);

private:
	CAtlArray<CString> m_paths;

private:
	// TODO: It's not really the dialog's problem that this is a separate thread,
	// but I've got a dependency problem between calling DoModal and starting the thread.
	static DWORD __stdcall _ImportThread(CImportProgressDialog *pThis)
	{
		return pThis->ImportThread();
	}

	DWORD ImportThread();
	void RecursivelyBuildFileList(const CString &strParentPath, CAtlArray<CString> *pFiles);

// ImportProgressObserver
public:
	virtual void OnSearchStarted();
	virtual void OnFoundFile(const CString &strPath);
	virtual void OnSearchCompleted();
	virtual void OnImportStarted();
	virtual void OnImportFileStarted(const CString &strFilePath, int num, int denom);
	virtual void OnDisplayThumbnail(Image *pThumbnail);
	virtual void OnImportCompleted();
};
